package peer.p2pnet.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteLongSwitch;
import peer.tools.ByteShortSwitch;

public class TimeSynMessage2 extends Message{
	public short sType=peer.tools.MessageType.sType_TimeSynMessage2;
	byte[] dpData=new byte[12];
	long nowTime;
	public TimeSynMessage2(){
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		ByteLongSwitch.toByteArray(System.currentTimeMillis(), dpData, 4);
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public long getTime (){
		return nowTime; 
	}
	
	public TimeSynMessage2(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		nowTime=ByteLongSwitch.toLong(dpData, 4);
	}
}
